//
//  SetPhotoController.m
//  Arts1
//
//  Created by apple on 15/9/24.
//  Copyright © 2015年 Arts1. All rights reserved.
//

#import "SetPhotoController.h"
#import "PhotoChooseController.h"

#import "RegisterInfoController.h"
#import "AllHeader.h"


@interface SetPhotoController ()

/**
 *  添加背景模糊视图
 */
@property (nonatomic ,strong) UIVisualEffectView *visualEffectView;
/**
 *  选择拍照或相册
 */
@property (nonatomic ,strong) PhotoChooseController *photoChooseVC;

/**
 *  完整用户信息页面
 */
@property (nonatomic ,strong) RegisterInfoController *registerInfo;

@end

@implementation SetPhotoController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createVisualEffectView];
    
    [self creactTableView];
    // Do any additional setup after loading the view.
}

/**
 *  点击移除模糊页面
 */
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    // 通过响应者链找到要操作的对象，直接进行事件的操作，通常是找到目标controller进行push，present，pop，dismiss 这些操作，也可以修改目标controller的属性，以及调用方法，传值
    UITouch *touch = (UITouch *)[touches anyObject];
    CGPoint point = [touch locationInView:_visualEffectView];
    if (point.x < _photoChooseVC.view.left || point.x > _photoChooseVC.view.right || point.y < _photoChooseVC.view.top || point.y > _photoChooseVC.view.bottom  ) {
        UIResponder *responder = [self.view nextResponder];
        while (responder)
        {
            if ([responder isKindOfClass:[RegisterInfoController class]])
            {
                [self.view removeFromSuperview];
            }
            responder = [responder nextResponder];
        }
    }
}

/**
 *  创建相册或相机页面选择页面
 */
- (void)creactTableView
{
    _photoChooseVC = [[PhotoChooseController alloc] initWithStyle:(UITableViewStylePlain)];
    _photoChooseVC.view.frame = CGRectMake(53 * WIDTH, 230 * HEIGHT, 270 * HEIGHT, 132 * HEIGHT);
    _photoChooseVC.view.layer.cornerRadius = 10;
    _photoChooseVC.tableView.scrollEnabled = NO;
    [UIView viewShadowColor:_photoChooseVC.view];
    [self.view addSubview:_photoChooseVC.view];
    
    __weak SetPhotoController *wUserLGVC = self;
    _photoChooseVC.choosephotoblock = ^(NSInteger num){
        
        if (num == 0)
        {
            //调用相册方法
            wUserLGVC.photoBlock(0);
        }
        else
        {
            //调用相机方法
            wUserLGVC.photoBlock(1);
        }
    };
}

// 毛玻璃效果
- (void)createVisualEffectView
{
    UIVisualEffect *lightBlurEffect = [UIBlurEffect effectWithStyle:(UIBlurEffectStyleLight)];
    _visualEffectView = [[UIVisualEffectView alloc] initWithEffect:lightBlurEffect];
    _visualEffectView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    _visualEffectView.alpha = 1;
    [self.view addSubview:_visualEffectView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
